from fastapi import  Request, APIRouter
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates

tmp = APIRouter()


# 初始化 Jinja2Templates 实例，并指定模板文件的位置
templates = Jinja2Templates(directory="templates")

@tmp.get("/", response_class=HTMLResponse)
async def read_item(request: Request):
    return templates.TemplateResponse("index.html", {"request": request,
                                                     "title": "FastAPI with Jinja2"}
                                      )
